package com.carepad.action.home;

import java.text.ParseException;

import com.carepad.action.AbstractManagementAction;
import com.carepad.entity.mapper.SelectClient;
import com.carepad.util.SessionKey;


public class HomeViewAction extends AbstractManagementAction{

	private static final long serialVersionUID = 1L;
	
	public String execute() throws ParseException {
		
		SelectClient patient = getSessionPatient();
		
		if(patient == null){
			
			String clientUID = getCookie("CLIENTUID");
			
			if(clientUID != null)
			{
				patient = getPatientByUid(clientUID);			
				addSessionVariable(patient);
			}
		}		
		
		setImplementationDate("SetByCookie");
		
		return SUCCESS;
	}
	
	public String completeSession() throws ParseException {
		
		deleteAllCookies();
		removeSessionVariable(SessionKey.CURRENT_PATIENT);
		removeSessionVariable(SessionKey.IMPLEMENTATION_DATE);
		setImplementationDate("SetByCookie");
		
		return SUCCESS;
	}
}
